package com.corpcredit.webapp.action;

import java.io.Serializable;
import java.util.Date;

import com.corpcredit.Constants;
import com.corpcredit.model.GlryZyjyglr;
import com.corpcredit.webapp.action.BasePage;
import com.corpcredit.service.GenericManager;

public class GlryZyjyglrForm extends BasePage implements Serializable {
    private GenericManager<GlryZyjyglr, Long> glryZyjyglrManager;
    private GlryZyjyglr glryZyjyglr = new GlryZyjyglr();
    private Long id;

    public void setGlryZyjyglrManager(GenericManager<GlryZyjyglr, Long> glryZyjyglrManager) {
        this.glryZyjyglrManager = glryZyjyglrManager;
    }

    public GlryZyjyglr getGlryZyjyglr() {
        return glryZyjyglr;
    }

    public void setGlryZyjyglr(GlryZyjyglr glryZyjyglr) {
        this.glryZyjyglr = glryZyjyglr;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String delete() {
        glryZyjyglrManager.remove(glryZyjyglr.getId());
        addMessage("glryZyjyglr.deleted");

        return "list";
    }

    public String edit() {
        // Comparison to zero (vs. null) is required with MyFaces 1.2.2, not with previous versions
        if (id != null && id != 0) {
            glryZyjyglr = glryZyjyglrManager.get(id);
        } else {
            glryZyjyglr = new GlryZyjyglr();
        }

        return "edit";
    }

    public String save() {
        boolean isNew = (glryZyjyglr.getId() == null || glryZyjyglr.getId() == 0);
        
        //dwtz.setJbqk(jbqk);
        glryZyjyglr.setUsername(getRequest().getRemoteUser());
        glryZyjyglr.setOptdate(new Date());
        glryZyjyglr.setOperation(isNew?Constants.OPERATION_ADD:Constants.OPERATION_UPDATE);
        

        
        glryZyjyglrManager.save(glryZyjyglr);

        String key = (isNew) ? "glryZyjyglr.added" : "glryZyjyglr.updated";
        addMessage(key);

        if (isNew) {
            return "list";
        } else {
        	this.id=this.glryZyjyglr.getId();
            return edit();

        }
    }
} 